﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Gatheshop.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Gatheshop.Web.Plugin.Feedback.Model;
using Gatheshop.Web.Plugin.Feedback.BLL;
using Gatheshop.Common;

namespace Gatheshop.Web.Plugin.Feedback.admin
{
    public class reply : ManagePage
    {
        // Fields
        protected Button btnSubmit;
        protected HtmlForm form1;
        private int id = 0;
        protected feedback model = new feedback();
        protected TextBox txtReContent;

        // Methods
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            feedbackBLL feedback = new feedbackBLL();
            this.model = feedback.GetModel(this.id);
            this.model.reply_content = Utils.ToHtml(this.txtReContent.Text);
            this.model.reply_time = new DateTime?(DateTime.Now);
            feedback.Update(this.model);
            base.JscriptMsg("留言回复成功啦！", "index.aspx", "Success");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!int.TryParse(base.Request.QueryString["id"], out this.id))
            {
                base.JscriptMsg("传输参数不正确！", "back", "Error");
            }
            else if (!new feedbackBLL().Exists(this.id))
            {
                base.JscriptMsg("信息不存在或已被删除！", "back", "Error");
            }
            else if (!this.Page.IsPostBack)
            {
                this.ShowInfo(this.id);
            }
        }

        private void ShowInfo(int _id)
        {
            this.model = new feedbackBLL().GetModel(_id);
            this.txtReContent.Text = Utils.ToTxt(this.model.reply_content);
        }
    }


}